﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GreedySnake.UI.View.ViewEx
{
    internal class Cell : ICloneable
    {
        public Point Point { get; set; }
        private Direction _curDirection = Direction.Right;
        public Direction SnakeDirection
        {
            get => _curDirection;
            set
            {
                _curDirection = value;
                UpdatePoint();
            }
        }
        public void UpdatePoint()
        {
            (int dx, int dy) = GetPoint(_curDirection);
            Point = new Point(Point.X + dx, Point.Y + dy);
        }
        public (int dx, int dy) GetPoint() => GetPoint(_curDirection);
        public (int dx, int dy) GetPoint(Direction direction)
        {
            int dx = 0, dy = 0;
            if (direction == Direction.Left)
                dx = -1;
            else if (direction == Direction.Right)
                dx = 1;
            else if (direction == Direction.Top)
                dy = -1;
            else if (direction == Direction.Bottom)
                dy = 1;
            return (dx, dy);
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}
